# Script to run QAP
library(sna)
library(doParallel)
library(doRNG)
library(fastglm)

source("fast_qap.R")

# Load the followers adjacency matrix
y <- readRDS("processed_data/followers_adjacencyMatrix.Rds")
# Load the predicting matrices
load("processed_data/QAP_predicting_matrices.RData")
# load simulated edgelists
load("simulated_follower_networks.RData")

# Parallel implementation to run QAP
cl <- makeCluster(3)
registerDoParallel(cl)
set.seed(10)
system.time(qap_res <- foreach(i=26:50,.packages=c("sna", "doRNG","fastglm")) %dorng% {
  ys <- y
  ys[,] <- 0
  ys[as.matrix(sim_els[[i]])] <- 1
  qap_sim <- netlogit_big(ys, predicting_matrices, reps = 100,nullhyp="qapy")
  save(list="qap_sim",file=paste("./qap_power_results/qap_sim_follow",i,".RData",sep=""))
})
stopCluster(cl)




